package login;

import java.io.*;
import java.util.List;

import javax.ejb.EJB;
import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.*;

import model.User;
import model.UserService;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
	
	@EJB
	private UserService userService; 

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		
		HttpSession session = request.getSession(true);
		session.setAttribute("userid", "Sanya");
		
		response.sendRedirect("index.jsp");
		
	}

	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	
		response.setContentType("text/html");
		
		//String action = request.getParameter("action");
		
		List<User> allUsers = userService.getAllUsers();
		
		PrintWriter out = response.getWriter();
		for(User u : allUsers){
			out.println("User - " + u.getContent() + "<br />");			
		}
		
//		
	}
}
